package com.itxx.homeWork;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class AnnoDemo3 {
    public static void main(String[] args) throws IllegalAccessException, InstantiationException, InvocationTargetException {
        //创建Class对象
        Class<AnnoTest> annoTestClass = AnnoTest.class;
        //获取所有方法
        Method[] declaredMethods = annoTestClass.getDeclaredMethods();
        //遍历方法数组
        for (Method declaredMethod : declaredMethods) {
            //判断方法上有没有Test注解
            boolean result = declaredMethod.isAnnotationPresent(Test.class);
            if(result){
                //true  表示有  执行方法
                declaredMethod.invoke(annoTestClass.newInstance());
            }
        }
    }
}
